package com.nervenets.web.entity;


import com.nervenets.web.controller.handler.ApiParams;
import com.nervenets.web.enumeration.Method;
import com.nervenets.web.enumeration.Role;

import java.util.ArrayList;
import java.util.Objects;

/**
 * Created by joe on 17-3-12.
 */
public class ParamModel extends Model {
    private Method method;
    private ApiParams parameter;
    private boolean authority;
    private boolean deprecated;
    private String roles;
    private String result;

    public ParamModel() {
    }

    public ParamModel(Method method, ApiParams parameter, String result) throws InstantiationException, IllegalAccessException {
        this.method = method;
        this.parameter = parameter;
        this.authority = Objects.requireNonNull(method.getHandler()).isAuthority();
        this.result = result;
        if (authority) {
            ArrayList list = method.getHandler().getRoles();
            StringBuilder buffer = new StringBuilder();
            for (Object o : list) {
                Role role = (Role) o;
                buffer.append("[").append(role.getLabel()).append("]");
            }
            this.roles = buffer.toString();
        }
        this.deprecated = method.isDeprecated();
    }

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
    }

    public ApiParams getParameter() {
        return parameter;
    }

    public void setParameter(ApiParams parameter) {
        this.parameter = parameter;
    }

    public boolean isAuthority() {
        return authority;
    }

    public void setAuthority(boolean authority) {
        this.authority = authority;
    }

    public String getRoles() {
        return roles;
    }

    public void setRoles(String roles) {
        this.roles = roles;
    }

    public boolean isDeprecated() {
        return deprecated;
    }

    public void setDeprecated(boolean deprecated) {
        this.deprecated = deprecated;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }
}
